<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Course extends Model
{
    use HasFactory;
    protected $table = 'course';
    const TYPE_COURSE = 1;
    const TYPE_LIVE = 2;
    public static $typeMap = [
        self::TYPE_COURSE => '课程',
        self::TYPE_LIVE => '直播'
    ];
    protected $fillable = [
        'name',
        'type',
        'thumb',
        'is_recommend',
        'description',
        'content',
        'sort'
    ]; 

    protected $hidden = [
        'laravel_through_key'
     ];
    public function lesson()
    {
        return $this->hasMany(CourseLesson::class, 'course_id');
    }
    public function subject()
    {
        return $this->hasOne(Subject::class, 'id', 'subject_id')->select('id', 'name');
    }
}
